package com.ggh.jinjilive.dialog;

import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.ViewGroup;
import android.view.Window;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.ggh.jinjilive.R;
import com.ggh.jinjilive.dialog.adapter.CreateChannelAdapter;
import com.ggh.jinjilive.listener.AddItemOnClickListener;
import com.ggh.jinjilive.mobile.home.live.LiveCategory;
import com.cy.dialog.BaseDialog;

import java.util.List;

public class CreateChannelDialog extends BaseDialog {
    private RecyclerView rv;
    private CreateChannelAdapter createChannelAdapter;

    public CreateChannelDialog(Context context) {
        super(context);
    }

    public CreateChannelDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        contentView(R.layout.dialog_create_channel);
        canceledOnTouchOutside(true);
        animType(AnimInType.BOTTOM);
        rv = findViewById(R.id.rv);

        createChannelAdapter = new CreateChannelAdapter();
        createChannelAdapter.setAddItemOnClickListener(new AddItemOnClickListener() {
            @Override
            public void onSkipClicked(int position, Object mObject) {
                if(null != addItemOnClickListener){
                    addItemOnClickListener.onSkipClicked(position,mObject);
                }
            }
        });
        rv.setLayoutManager(new LinearLayoutManager(getContext()));
        rv.setAdapter(createChannelAdapter);
    }

    /**
     * 设置数据
     * @param liveCategoryList
     */
    public void setLiveCategory(List<LiveCategory> liveCategoryList,LiveCategory liveCategory){
        if(null != createChannelAdapter){
            createChannelAdapter.setAdd(liveCategoryList,liveCategory);
        }
    }




    private AddItemOnClickListener addItemOnClickListener;
    public void setAddItemOnClickListener(AddItemOnClickListener addItemOnClickListener) {
        this.addItemOnClickListener = addItemOnClickListener;
    }


    @Override
    public void show() {
        super.show();
        Window window = getWindow();
        //设置弹出位置
        window.setGravity(Gravity.BOTTOM);
        //设置对话框大小
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    }
}
